from typing import Dict, Type
from engine_server.config.base import IConfig, BaseConfig, ServerConfig


class ConfigParser:
    def __init__(self, server_config: ServerConfig):
        self.server_config = server_config
        self._config_class_map: Dict[str, Type[BaseConfig]] = {
            "vllm": self._import_vllm_config(),
        }

    def _import_vllm_config(self):
        from engine_server.config.vllm import VLLMConfig
        return VLLMConfig

    def parse(self) -> IConfig:
        engine_type = self.server_config.engine_type
        config_class = self._config_class_map.get(engine_type)

        if not config_class:
            raise ValueError(
                f"Unsupported engine type: {engine_type}, supported types: {list(self._config_class_map.keys())}")

        config_instance = config_class(server_config=self.server_config)

        config_instance.convert()
        config_instance.validate()
        return config_instance
